#include <bits/stdc++.h>
using namespace std;
int T,n,a[200010],t[1000010],maxx;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin.tie(0)->sync_with_stdio(false);
    cin>>T;
    while(T--){
        int sum=0;
        memset(t,0,sizeof(t));
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            t[a[i]]++;
            maxx=max(maxx,a[i]);
        }
        for(int i=1;i<=maxx;i++){
            if(t[i]>1){
                sum+=i;
            }
        }
        cout<<sum<<'\n';
    }
    return 0;
}
